package sms;

import com.jasson.im.api.APIClient;

/**
 * @author FuXuan 2010-5-19 Copyright by Sinobest
 */
public class SmsServiceImpl {

	// TODO 短信数据库需从配置文件(src-resources/sms.properties)中读取

	private final String dbIP = "19.16.84.2";
	private final String dpip1 = "19.16.84.2";
	// private final String dbIP = "19.16.86.14";
	private final String dbName = "mas";
	private final String apiCode = "mzxtptsms";
	private final String dbUser = "mzxtpt";
	private final String dbPwd = "mzxtpt123";

	private static final String SMS_PROPERTIES_NAME = "sms.properties";

	private static final String PROPERTIES_NOT_EXIST_MSG = "请检查短信配置文件是否存在";

	private static final String PROPERTIES_INCORRECT_MSG = "连接失败,请检查短信配置文件是否正确";

	private static final String ERROR_CODE_MSG = "--错误代码";

	private final APIClient handler = new APIClient();

	public SmsServiceImpl() {
		if (dbIP != null && dbName != null && apiCode != null && dbUser != null
				&& dbPwd != null) {
			int connectRe = handler.init(dbIP, dbUser, dbPwd, apiCode, dbName);
			if (connectRe != APIClient.IMAPI_SUCC) {
				System.out.println(PROPERTIES_INCORRECT_MSG + ERROR_CODE_MSG
						+ connectRe);
			} else {
				System.out.println("连接成功");
			}
		} else {
			System.out.println(PROPERTIES_INCORRECT_MSG);
		}
	}

	public boolean send(String sendto, String content) {
		int result = handler.sendSM(sendto, content, 1);

		if (result == APIClient.IMAPI_SUCC) {
			return true;
		}

		return false;
	}

	public static void main(String args[]) {
		SmsServiceImpl ssi = new SmsServiceImpl();
		ssi.send("13570427298", "测试内容123214");
	}

}
